package model;

import java.util.ArrayList;

public class NetworkInterface extends Device {
	
	/**
	 * Il nodo che ospita questa interfaccia
	 */
	private Node parent;
	
	/**
	 * Gli indirizzi IP associati all'interfaccia.
	 */
	private ArrayList<IPAddress> ipAddresses = new ArrayList<IPAddress>(0);
	
	/**
	 * Gli indirizzi MAC associati all'interfaccia
	 */
	protected MacAddress macAddress;
	
	/**
	 * L'indirizzo di controllo definito su questa interfaccia, se presente.
	 */
	private IPAddress controlAddress = null;
	
	public NetworkInterface(String name, MacAddress mac) {
		super(name);
		this.macAddress = mac;
	}

	
//	abstract public MacAddress getMacAddress();
//	
//	abstract public String getXMLDescription();
//	
//	abstract public void setParent(Node node);
//	
//	abstract public Node getParent();
	

	/* METODI GIA IMPLEMENTATI IN NEPTUNE*/
	public Node getParent() {
		return parent;
	}

	public Address getAddress(Address address) {
		return ipAddresses.get(ipAddresses.indexOf(address));
	}
	
	public IPAddress[] getIpAddresses() {
		return (IPAddress[]) ipAddresses.toArray(new IPAddress[0]);
	}
	
	public IPAddress getControlAddress() {
		return controlAddress;
	}
	
	public MacAddress getMacAddress() {
		return macAddress;
	}
	
	public void setParent(Node parent) {
		this.parent = parent;
	}
	
	public void addIpAddress(IPAddress ipAddress) {
		if (ipAddress.isControlAddress())
			controlAddress = ipAddress;

		this.ipAddresses.add(ipAddress);
	}
	
	public void setMacAddress(MacAddress macAddress) {
		this.macAddress = macAddress;
	}
	
	public boolean hasMacAddress(MacAddress macAddress) {
		if (this.macAddress.equals(macAddress))
			return true;
		else
			return false;
	}
}
